<script setup>
import useTaskStore from "@/pinia/modules/taskStore";
import { onMounted, reactive } from "vue";
import { storeToRefs } from "pinia";

const props = defineProps({
  status: {
    type: Number,
  },
});

const taskStore = useTaskStore();

const { deliveryList } = storeToRefs(taskStore);

const params = reactive({
  status: props.status,
  page: 1,
  pageSize: 10,
});


const fetchDeliveryList = async () => {
  try {
    await taskStore.fetchDeliveryList(params);
  } catch (error) {
    uni.showToast({ title: error.message, duration: 2000, icon: "error" });
  }
};

onMounted(() => {
  fetchDeliveryList();
});

</script>

<template>
  <scroll-view scroll-y refresher-enabled class="scroll-view">
    <view class="scroll-view-wrapper">
      <view class="task-card" v-for="(item) in deliveryList" :key="item.id">
        <navigator hover-class="none" :url="`/subpkg_task/detail/index?id=${item.id}`">
          <view class="header">
            <text class="no">任务编号:{{ item.transportTaskId }}</text>
            <text class="status" v-if="item.status===2">在途</text>
            <text class="status" v-if="item.status===4">登记</text>
          </view>
          <view class="body">
            <view class="timeline">
              <view class="line">{{ item.startAddress }}</view>
              <view class="line">{{ item.endAddress }}</view>
            </view>
          </view>
        </navigator>
        <view class="footer">
          <view class="label">提货时间</view>
          <view class="time">{{ item.created }}</view>
          <navigator hover-class="none" :url="`/subpkg_task/delivery/index?id=${item.id}`" class="action" v-if="item.status===2">交付</navigator>
          <navigator hover-class="none" :url="`/subpkg_task/record/index?transportTaskId=${item.transportTaskId}&actualDepartureTime=${item.actualDepartureTime}`" class="action" v-if="item.status===4">回车登记</navigator>
        </view>
      </view>
      <view v-if="!deliveryList" class="task-blank">无在途货物</view>
    </view>
  </scroll-view>
</template>

<style lang="scss" scoped>
@import './styles.scss';
</style>
